/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cart;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.ServletContext;
import javax.servlet.RequestDispatcher;

/**
 *
 * @author frank
 */
public class RemoveItemServlet extends HttpServlet {
    
    @Override
    public void service(HttpServletRequest request,
            HttpServletResponse response)
            throws IOException, ServletException {

        int itemIndex = Integer.parseInt(request.getParameter("item"));

        HttpSession session = request.getSession();


        ShoppingCart cart = (ShoppingCart) session.getAttribute("ShoppingCart");

        cart.removeItem(itemIndex);


        String url = "/ShowProductCatalog.jsp";
        ServletContext sc = getServletContext();
        RequestDispatcher rd = sc.getRequestDispatcher(url);
        rd.forward(request, response);
    }
} 
